package io.renren.modules.backstage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.exception.Result;
import io.renren.common.exception.StatusCode;
import io.renren.modules.backstage.dao.RepaymentLogDao;
import io.renren.modules.backstage.entity.RepaymentLogEntity;
import io.renren.modules.backstage.service.RepaymentLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("repaymentLogService")
public class RepaymentLogServiceImpl implements RepaymentLogService {

    @Autowired
    RepaymentLogDao repaymentLogDao;


    /**
     * 根据借款ID查询还款信息
     * @param repaymentLogEntity
     * @return
     */
    @Override
    public Result getRepaymentLogList(RepaymentLogEntity repaymentLogEntity) {

        Page<RepaymentLogEntity> page = new Page<>(repaymentLogEntity.getPageNum(),repaymentLogEntity.getPageSize());
        QueryWrapper<RepaymentLogEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("borrow_id",repaymentLogEntity.getBorrowId());
        Page<RepaymentLogEntity> entityPage =repaymentLogDao.selectPage(page, queryWrapper);
        return new Result(StatusCode.OK,"还款数据日志查询成功",true,entityPage);
    }

    @Override
    public Result getAll() {
        List<RepaymentLogEntity> entityList = repaymentLogDao.selectList(null);
        return new Result(StatusCode.OK,"还款数据日志查询成功",true,entityList);
    }
}
